﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
namespace DAO
{
    public class ViewCartDAO
    {
        public List<Monhang> list;
        public ViewCartDAO() {
            list = new List<Monhang>();
        }

        private int index(List<Monhang> ds, Monhang mh) {
            int i = -1;
            for (int j = 0; j < ds.Count; j++) {
                Monhang h = (Monhang)ds[j];
                if (h.products.id == mh.products.id)
                    return j;
            }
            return i;
        }

        public void Add(Monhang mh) {
            int i = index(list, mh);
            if (i == -1)
            {
                list.Add(mh);
            }
            else {
                Monhang h = (Monhang)list[i];
                h.soluong = h.soluong + mh.soluong;
            }
        }

        public void Delete(Monhang mh) {
            int i = index(list, mh);
            if (i != -1)
                list.RemoveAt(i);
        }
    }
}
